package com.joney.mq.web;


import com.joney.mq.activemq.Producer;
import com.joney.mq.pojo.Content;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Destination;
import java.util.Date;

/**
 * @author wangxianchen
 * @create 2018-03-06
 * @desc
 */
@RestController
public class ActivemqController {

    @Autowired
    private Producer producer;

    @RequestMapping("test/{msg}")
    public String test(@PathVariable("msg") String msg){
        Destination destDirect = new ActiveMQQueue("direct.queue"); //创建点对点模式
        Content content = new Content();
        content.setId(System.currentTimeMillis());
        content.setBody("消息内容");
        content.setDate(new Date());
        producer.send(destDirect,content);

        Destination destTopic = new ActiveMQTopic("topic.queue"); //创建发布订阅模式
        producer.send(destTopic,msg);

        return "success";
    }

}
